package com.quick.develop.flowable.mapper;

import com.quick.develop.flowable.domain.entrust.BpmEntrustDueReqVO;
import com.quick.develop.flowable.domain.entrust.BpmEntrustEx;
import com.quick.develop.flowable.domain.entrust.BpmEntrustExPageReqVO;
import com.quick.develop.flowable.domain.entrust.BpmEntrustInfoReqVO;
import com.quick.develop.flowable.utils.mybatis.mapper.BaseMapperX;
import com.quick.develop.flowable.utils.mybatis.query.LambdaQueryWrapperX;
import com.quick.develop.framework.common.page.PageResult;

import java.util.List;

/**
 * @author junyuan.liu
 * @description:
 * @date 2022/9/4 14:39
 */
public interface BpmEntrustExMapper extends BaseMapperX<BpmEntrustEx> {
    
    default PageResult<BpmEntrustEx> selectPage(BpmEntrustExPageReqVO reqVO, String userCode) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BpmEntrustEx>()
                .eq(BpmEntrustEx::getCreatedUserCode, userCode)
                .likeIfPresent(BpmEntrustEx::getModelName, reqVO.getModelName())
                .likeIfPresent(BpmEntrustEx::getModelKey, reqVO.getModelKey())
                .betweenIfPresent(BpmEntrustEx::getStartDate, reqVO.getBeginStartDate(), reqVO.getEndStartDate())
                .betweenIfPresent(BpmEntrustEx::getEndDate, reqVO.getBeginEndDate(), reqVO.getEndEndDate()));
    }
    
    default long selectCountByKey(String key, String userCode) {
        return selectCount(new LambdaQueryWrapperX<BpmEntrustEx>()
                .eq(BpmEntrustEx::getModelKey, key)
                .eq(BpmEntrustEx::getCreatedUserCode, userCode));
    }
    
    default List<BpmEntrustEx> selectList(BpmEntrustInfoReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BpmEntrustEx>()
                .eq(BpmEntrustEx::getModelKey, reqVO.getModelKey())
                .inIfPresent(BpmEntrustEx::getCreatedUserCode, reqVO.getCreatedUsers())
                .eqIfPresent(BpmEntrustEx::getCreatedUserCode, reqVO.getCreatedUser())
                .le(BpmEntrustEx::getStartDate, reqVO.getEntrustDate())
                .ge(BpmEntrustEx::getEndDate, reqVO.getEntrustDate()));
    }
    
    default List<BpmEntrustEx> selectOverdueEntrust(BpmEntrustDueReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BpmEntrustEx>()
                .eqIfPresent(BpmEntrustEx::getModelKey, reqVO.getModelKey())
                .inIfPresent(BpmEntrustEx::getModelKey, reqVO.getModelKeys())
                .inIfPresent(BpmEntrustEx::getEntrustToUser, reqVO.getEntrustUsers())
                .eqIfPresent(BpmEntrustEx::getEntrustToUser, reqVO.getEntrustUser())
                .lt(BpmEntrustEx::getEndDate, reqVO.getDueDate())
        );
    }
}
